<!--
 * @Author: xlm
 * @Date: 2021-08-04 10:32:30
 * @LastEditors: xlm
 * @LastEditTime: 2021-08-04 17:06:07
 * @Description: 自定义数字键盘
-->
<template>
  <div class="keyboard">
    <div v-for="(item, index) in 9" :key="item" :class="['item', index % 3 === 0 ? 'noleft' : '']" @click="add(index + 1)">
      {{ index + 1 }}
    </div>
    <div class="item bg noleft"></div>
    <div class="item" @click="add(0)">0</div>
    <div class="item bg" @click="minus()">
      <b-image class="minus-icon" isAsset src="/static/images/icon/minus-icon.png"></b-image>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    str: {
      type: String,
      default: ''
    }
  },
  methods: {
    add(char) {
      this.$emit('changeStr', char)
    },
    minus() {
      this.$emit('changeStr', -1)
    }
  }
}
</script>

<style lang="scss" scoped>
.keyboard {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  position: absolute;
  left: 0;
  width: 100vw;
  bottom: 0;
  .item {
    height: 110rpx;
    line-height: 110rpx;
    text-align: center;
    width: 33.33%;
    border-top: 1px solid #bbbbbb;
    border-left: 1px solid #bbbbbb;
    box-sizing: border-box;
    font-size: 50rpx;
    font-weight: 500;
    position: relative;
    &.bg {
      background: #e5e7ec;
    }
    &.noleft {
      border-left: none;
    }
  }
}
.minus-icon {
  width: 50rpx;
  height: 35rpx;
  // display: block;
  // margin: 38rpx auto; //h5与微信小程序表现不一致
  // display: flex;
  // justify-content: center;
  // align-items: center;
  display: block;
  //   position: absolute;
  //   left: 50%;
  //   top: 50%;
  //   transform: translate(-50%, -50%);
  margin: 0 auto;
  margin-top: 38rpx;
  // 兼容编译后的微信小程序
  font-size: 0;
  line-height: 0;
}
</style>
